package com.lizhangjun.nim.listener;

import com.alibaba.fastjson.JSON;
import com.lizhangjun.nim.constant.IMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Slf4j
@Component
public class RedisMQMsgListener implements MessageListener {

    @Override
    public void onMessage(@NonNull Message message, byte[] bytes) {
        //推送
        String mqData = new String(message.getBody(), StandardCharsets.UTF_8);
        IMessage iMessage = JSON.parseObject(mqData, IMessage.class);
        Sender.getSender().send(iMessage);
    }
}
